package com.thread;

/**
 * @author :admin
 * @description: 存在多线程问题，2个线程同时去访问，一个存钱一个取钱，所以必须要有一个先手顺序
 * @create date: 2019/8/11 11:28
 */
public class SyncDemo {

    public static void main(String[] args){
        ATM atm=new ATM();
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50; i++) {
                    atm.addMoeny(100);
                }
            }
        });
        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50; i++) {
                    atm.getMoeny(100);
                }
            }
        });
        t1.start();
        t2.start();
    }
}
